package com.yao.club.mapper;

import com.yao.club.entity.Topic;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface PostsTopicMapper {
    @Select("select * from posts_topic where topicId=#{topicId}")
    Topic selectById(@Param("topicId") String topicId);

    @Select("select * from posts_topic limit #{limit}")
    List<Topic> selectTopics(@Param("limit") int limit);


    /**
     * 搜索相关话题
     * 模糊匹配话题名称，按照帖子数量和创建时间排序
     */
    @Select("SELECT  * from posts_topic  " +
            "WHERE topicName  LIKE CONCAT('%', #{keyword}, '%') " +
            "LIMIT 10")
    List<Topic> searchTopics(String keyword);
}
